//
//  DevicePrepaireReportTwo.m
//  DevicePrepaireReportTwo
//
//  Created by MacBook Pro on 16/8/2.
//  Copyright © 2016年 郭同博. All rights reserved.
//
//屏幕的宽
#define SCREENW self.view.bounds.size.width
//屏幕的高
#define SCREENH self.view.bounds.size.height
#define Margin 5
#define LineLen 1;

// RGB颜色
#define TBColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]


#import "DevicePrepaireReportTwoViewController.h"
#import "NrowLabelMessage.h"
#import "NrowLabelViewCell.h"
#import "RSCheckBox.h"
#import "RSCheckGroup.h"
#import "MyButton.h"
#import "TouchView.h"
#import "PullMenu.h"
#import "SignsViewController.h"
#import "ServeRecordCell.h"
#import "ServeRecordArr.h"
#import "CurrentServeReprotMessage.h"
#import "CurrentServeReprotMessage.h"

@interface DevicePrepaireReportTwoViewController ()<UITableViewDelegate,UITableViewDataSource,UIPickerViewDelegate,UIPickerViewDataSource>{
    /**邮箱*/
    UIButton *emailBtn;
    /**邮箱线*/
    UIView *emailLine;
    /**邮件地址Label*/
    UILabel *emailLabel;
    /**邮箱数组*/
    NSMutableArray *emailArr;
    /**邮箱menuStr*/
    NSString *menuStr;
    /**邮箱textField*/
    UITextField *emailTextF;
    /**保存*/
    UIButton *saveBtn;
    /**提交 */
    UIButton *sumbitBtn;
    /**预览*/
    UIButton *previewBtn;
    /**数据*/
    NSArray *info;
    /**区头*/
    NSMutableDictionary *header;
    /**tableView*/
    UITableView *tableV;
    /**服务分类*/
    UIButton *serveTypeBtn;
    /**服务分类数组*/
    NSArray *serveTypeBtnArr;
    /**服务分类字符串*/
    NSString *serveTypeStr;
    /**单选按钮类型View*/
    UIPickerView *singleView;
    /**服务完成状态数据数组*/
    NSArray *serveFinishArr;
    /**服务完成状态Btn*/
    UIButton *serveFinishBtn;
    /**已完成*/
    BOOL isFinish;
    /**未完成*/
    BOOL isUnFinish;
    /**服务完成状态字符串*/
    NSString *serveFinishStr;
    /**区脚View*/
    UIView *footView;
    /**签名图片*/
    UIImageView *signImgView;
    /**触屏*/
    TouchView *TouchV;
    /**是否非诚满意*/
    BOOL isVerySatisfied;
    /**非常满意btn*/
    UIButton *VerySatisfiedBtn;
    /**满意btn*/
    UIButton *satisfiedBtn;
    /**是否满意*/
    BOOL isSatisfied;
    /**一般btn*/
    UIButton *normalBtn;
    /**是否一般*/
    BOOL isNormal;
    /**不满意btn*/
    UIButton *unSatisfiedbtn;
    /**是否不满意*/
    BOOL isUnsatisfied;
    /**满意度数据数组*/
    NSArray *satisfiedArr;
    /**满意度字符串*/
    NSString *satisfiedStr;

}
@end

@implementation DevicePrepaireReportTwoViewController
/**服务行为报告模型*/
@synthesize nLM;
/**服务记录的模型数组*/
@synthesize serveRecordArr;
/**服务记录数组的模型*/
@synthesize serveRecord;
/**AS现场服务报告模型*/
@synthesize currentServeReprot;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.title = @"设备维修单";
    self.view.backgroundColor = [UIColor whiteColor];
    //取数据
    [self GetData];
    //搭建界面
    [self setUpInterface];
    //改变导航栏的颜色、字体
    [self initNav];

    
}
-(void)initNav{
    
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:93/255.0 green:199/255.0 blue:255/255.0 alpha:1.0]];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]];
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    
}
//取数据
-(void)GetData{
    NSString *path = [[NSBundle mainBundle]pathForResource:@"DevicePrepairTwo" ofType:@"plist"];
    info = [NSArray arrayWithContentsOfFile:path];
    header = [NSMutableDictionary dictionary];
    serveRecordArr = [NSMutableArray array];
    serveRecord = [[ServeRecordArr alloc]init];
    nLM = [[NrowLabelMessage alloc]init];
    currentServeReprot = [[CurrentServeReprotMessage alloc]init];
}
//搭建界面
-(void)setUpInterface{
    
    //top和下面的按钮
    [self setUpBaseInfo];
    tableV = [[UITableView alloc]initWithFrame:CGRectMake(0,emailLine.frame.origin.y + 2 , SCREENW, saveBtn.frame.origin.y - emailLine.frame.origin.y + 1)style:UITableViewStyleGrouped];
    tableV.separatorStyle = NO;
    tableV.delegate = self;
    tableV.dataSource = self;
    tableV.bounces = NO;
    
    //tableV.style = UITableViewStyleGrouped;
    [self.view addSubview:tableV];
    // 设置额外滚动区域
    tableV.contentInset = UIEdgeInsetsMake(0, 0, 300, 0);
    
}
//基本信息
-(void)setUpBaseInfo{
    //邮箱
    emailBtn = [[UIButton alloc]init];
    [emailBtn setImage:[UIImage imageNamed:@"c_7"] forState:UIControlStateNormal];
    CGFloat emailBtnX = SCREENW - 45;
    CGFloat emailBtnY = 69;
    CGFloat emailBtnW = 32;
    CGFloat emailBtnH = 32;
    emailBtn.frame = CGRectMake(emailBtnX, emailBtnY, emailBtnW, emailBtnH);
    [emailBtn addTarget:self action:@selector(sendEmail) forControlEvents:UIControlEventTouchUpInside ];
    
    [self.view addSubview:emailBtn];
    
    //邮箱线
    emailLine = [[UIView alloc]init];
    emailLine.backgroundColor = TBColor(212, 212, 212, 1);
    CGFloat emailLineX = 0;
    CGFloat emailLineY = emailBtnY + emailBtnH + Margin;
    CGFloat emailLineW = SCREENW;
    CGFloat emailLineH = LineLen;
    emailLine.frame = CGRectMake(emailLineX, emailLineY, emailLineW, emailLineH);
    [self.view addSubview:emailLine];
    
    //保存
    saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    saveBtn.backgroundColor = TBColor(237, 237, 237, 1);
    saveBtn.layer.borderColor = [UIColor grayColor].CGColor;
    saveBtn.layer.borderWidth = 1;
    CGFloat saveBtnX = 0;
    CGFloat saveBtnY = SCREENH - 64;
    CGFloat saveBtnW = SCREENW/3;
    CGFloat saveBtnH = 64;
    saveBtn.frame = CGRectMake(saveBtnX, saveBtnY, saveBtnW, saveBtnH);
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [saveBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [self.view addSubview:saveBtn];
    
    //提交
    sumbitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sumbitBtn.backgroundColor = TBColor(237, 237, 237, 1);
    CGFloat sumbitBtnX = saveBtnW - 1 ;
    CGFloat sumbitBtnY = saveBtnY;
    CGFloat sumbitBtnW = saveBtnW ;
    CGFloat sumbitBtnH = saveBtnH;
    sumbitBtn.frame = CGRectMake(sumbitBtnX, sumbitBtnY, sumbitBtnW, sumbitBtnH);
    [sumbitBtn setTitle:@"提交" forState:UIControlStateNormal];
    [sumbitBtn addTarget:self action:@selector(submitClick) forControlEvents:UIControlEventTouchUpInside];
    [sumbitBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [sumbitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    sumbitBtn.layer.borderColor = [UIColor grayColor].CGColor;
    sumbitBtn.layer.borderWidth = 1;
    [self.view addSubview:sumbitBtn];
    
    //预览
    previewBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    previewBtn.backgroundColor = TBColor(237, 237, 237, 1);
    CGFloat previewBtnX = sumbitBtnW * 2 - 2 ;
    CGFloat previewBtnY = sumbitBtnY;
    CGFloat previewBtnW = sumbitBtnW + 2 ;
    CGFloat previewBtnH = sumbitBtnH;
    previewBtn.frame = CGRectMake(previewBtnX, previewBtnY, previewBtnW, previewBtnH);
    [previewBtn setTitle:@"预览" forState:UIControlStateNormal];
    [previewBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [previewBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    previewBtn.layer.borderColor = [UIColor grayColor].CGColor;
    previewBtn.layer.borderWidth = 1;
    [self.view addSubview:previewBtn];
    emailArr = [NSMutableArray array];
    
}
//点击邮件事件
-(void)sendEmail{
    NSLog(@"发送了");
    NSLog(@"Email%@",emailArr);
    if (emailArr.count == 0) {
        UIView *emailView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
        emailView.tag = 7;
        emailView.backgroundColor = [UIColor clearColor];
        [self.view addSubview:emailView];
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(18, SCREENW / 3, SCREENW - 36, 150)];
        view.layer.backgroundColor = TBColor(94, 204, 250, 1).CGColor;
        view.layer.borderWidth = 1;
        view.backgroundColor = [UIColor whiteColor];
        [emailView addSubview:view];
        
        emailLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 5, SCREENW - 105, 30)];
        emailLabel.text = @"请输入邮箱地址:";
        [view addSubview:emailLabel];
        
        emailTextF = [[UITextField alloc]initWithFrame:CGRectMake(25, 40, SCREENW * 4/5, 30)];
        emailTextF.backgroundColor = TBColor(212, 212, 212, 1);
        [view addSubview:emailTextF];
        
        UILabel *textMargin = [[UILabel alloc]initWithFrame:CGRectMake(20, 40, 5, 30)];
        textMargin.backgroundColor = TBColor(212, 212, 212, 1);
        [view addSubview:textMargin];
        
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(SCREENW * 4/5 - 80, 90, 80, 30)];
        [btn setTitle:@"发送" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        btn.backgroundColor = TBColor(102, 85, 191, 1);
        [btn addTarget:self action:@selector(sendE) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:btn];
        
        UIButton *cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(40, 90, 80, 30)];
        [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [cancelBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        cancelBtn.backgroundColor = TBColor(102, 85, 191, 1);
        [cancelBtn addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:cancelBtn];
    }else{
        NSInteger emailPullMenuViewW = SCREENW - 36;
        UIView *emailPullMenuView = [[UIView alloc]initWithFrame:CGRectMake(18, SCREENW / 3, emailPullMenuViewW, 180)];
        emailPullMenuView.backgroundColor = [UIColor whiteColor];
        emailPullMenuView.layer.borderColor = [UIColor blackColor].CGColor;
        emailPullMenuView.layer.borderWidth = 1;
        emailPullMenuView.tag = 23;
        [self.view addSubview:emailPullMenuView];
        
        NSInteger menuW = SCREENW - 105;
        PullMenu *menu = [[PullMenu alloc]initWithFrame:CGRectMake(20, 25, menuW, 30)];
        menu.data = emailArr;
        [emailPullMenuView addSubview:menu];
        [menu setValueChangeBlock:^(NSString *text)
         {
             NSLog(@"%@",text);
             menuStr = text;
             
         }];
        menu.layer.borderColor = [UIColor blackColor].CGColor;
        menu.layer.borderWidth = 1;
        NSInteger sendBtnY = 150;
        NSInteger sendBtnH = 30;
        NSInteger sendBtnW = emailPullMenuViewW/3;
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(sendBtnW, sendBtnY, sendBtnW, sendBtnH)];
        [btn setTitle:@"发送" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        btn.backgroundColor = TBColor(237, 237, 237, 1);
        btn.layer.borderColor = TBColor(181, 181, 181, 1).CGColor;
        btn.layer.borderWidth = 1;
        [btn addTarget:self action:@selector(emaiPullsendE) forControlEvents:UIControlEventTouchUpInside];
        [emailPullMenuView addSubview:btn];
        
        UIButton *cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, sendBtnY, sendBtnW, sendBtnH)];
        [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [cancelBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        cancelBtn.backgroundColor = TBColor(237, 237, 237, 1);
        cancelBtn.layer.borderColor = TBColor(181, 181, 181, 1).CGColor;
        
        [cancelBtn addTarget:self action:@selector(emaiPullcancel) forControlEvents:UIControlEventTouchUpInside];
        [emailPullMenuView addSubview:cancelBtn];
        
        //邮箱添加
        UIButton *emailAddBtn = [[UIButton alloc]initWithFrame:CGRectMake(sendBtnW * 2, sendBtnY, sendBtnW, sendBtnH)];
        [emailAddBtn setTitle:@"添加" forState:UIControlStateNormal];
        [emailAddBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [emailAddBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        emailAddBtn.backgroundColor = TBColor(237, 237, 237, 1);
        emailAddBtn.backgroundColor = TBColor(237, 237, 237, 1);
        emailAddBtn.layer.borderColor = TBColor(181, 181, 181, 1).CGColor;
        
        [emailAddBtn addTarget:self action:@selector(emaiPullAdd) forControlEvents:UIControlEventTouchUpInside];
        [emailPullMenuView addSubview:emailAddBtn];
        
    }
}
//提交点击事件
-(void)submitClick{
    
    CurrentServeReprotMessage *submit = [[CurrentServeReprotMessage alloc]init];
    submit.department = currentServeReprot.department;
    submit.serviceId = self.serviceId;
    submit.customerName = currentServeReprot.customerName;
    submit.operatorStr = currentServeReprot.operatorStr;
    submit.contactAddress = currentServeReprot.contactAddress;
    submit.departLeader = self.strLinkMan;
    submit.eqSeq = currentServeReprot.eqSeq;
    submit.productName = currentServeReprot.productName;
    submit.descriptionStr = currentServeReprot.descriptionStr;
    submit.serviceType = currentServeReprot.serviceType;
    
    NSLog(@"----depart = %@",submit.serviceType);
    [ServerProvider currentServeReportSubmit:submit result:^(ServerReturnInfo *retInfo) {
        
    }];
}
//点击发送邮件按钮
-(void)sendE{
    
    UIApplication *app = [UIApplication sharedApplication];
    NSURL *url = [NSURL URLWithString:emailTextF.text];
    //[app openURL:url];
    [emailTextF addTarget:self action:@selector(sendClick:) forControlEvents:UIControlEventEditingDidEnd];
    UIView *subViews = [self.view viewWithTag:7];
    [subViews removeFromSuperview];
    
}
//menu发送
-(void)emaiPullsendE{
    UIApplication *app = [UIApplication sharedApplication];
    NSURL *url = [NSURL URLWithString:menuStr];
    //[app openURL:url];
    UIView *subViews = [self.view viewWithTag:23];
    [subViews removeFromSuperview];
}
//点击取消按钮
-(void)cancel{
    UIView *subViews = [self.view viewWithTag:7];
    [subViews removeFromSuperview];
}
//menu取消消失
-(void)emaiPullcancel{
    UIView *subViews = [self.view viewWithTag:23];
    [subViews removeFromSuperview];
}
//menu添加
-(void)emaiPullAdd{
    
    UIView *subViews = [self.view viewWithTag:23];
    [subViews removeFromSuperview];
    UIView *emailView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
    emailView.tag = 7;
    emailView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:emailView];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(18, SCREENW / 3, SCREENW - 36, 150)];
    view.layer.backgroundColor = TBColor(94, 204, 250, 1).CGColor;
    view.layer.borderWidth = 1;
    view.backgroundColor = [UIColor whiteColor];
    [emailView addSubview:view];
    
    emailLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 5, SCREENW - 105, 30)];
    emailLabel.text = @"请输入邮箱地址:";
    [view addSubview:emailLabel];
    
    emailTextF = [[UITextField alloc]initWithFrame:CGRectMake(25, 40, SCREENW * 4/5, 30)];
    emailTextF.backgroundColor = TBColor(212, 212, 212, 1);
    [view addSubview:emailTextF];
    
    UILabel *textMargin = [[UILabel alloc]initWithFrame:CGRectMake(20, 40, 5, 30)];
    textMargin.backgroundColor = TBColor(212, 212, 212, 1);
    [view addSubview:textMargin];
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(SCREENW * 4/5 - 80, 90, 80, 30)];
    [btn setTitle:@"发送" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    btn.backgroundColor = TBColor(102, 85, 191, 1);
    [btn addTarget:self action:@selector(sendE) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    
    UIButton *cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(40, 90, 80, 30)];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    cancelBtn.backgroundColor = TBColor(102, 85, 191, 1);
    [cancelBtn addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:cancelBtn];
    
}
//celltextField点击事件
-(void)textClick:(UITextField *)textField{
    //获取cell
    UITableViewCell *cell  = (UITableViewCell *)[[textField superview] superview];
    if ([textField.text isEqualToString:@""]||textField.text == nil) {
        
        UILabel *label = (UILabel *)[cell viewWithTag:2];
        label.textColor = [UIColor redColor];
        UIView *line = (UIView *)[cell viewWithTag:3];
        line.backgroundColor = [UIColor redColor];
        
    }else{
        UILabel *label = (UILabel *)[cell viewWithTag:2];
        label.textColor = [UIColor blackColor];
        UIView *line = (UIView *)[cell viewWithTag:3];
        line.backgroundColor = TBColor(212, 212, 212, 1);
    }
}

#pragma mark tableViewdelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return info.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 2) {
        NSLog(@"服务记录cell %lu",serveRecordArr.count);
        return serveRecordArr.count+ 1;
        
    }else{
    NSArray *groupInfo = info[section][@"info"];
    return groupInfo.count;
    }
}

#pragma mark 创建每一行的cell
//给cell赋值
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    if (indexPath.section == 2) {
        ServeRecordCell *cell = [ServeRecordCell ServeRecordCellWithTableView:tableView];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.indexPath = indexPath;
        cell.parentTwoController = self;
        cell.tableV = tableV;
        if (cell.indexPath.row == 0) {
            cell.delBtn.hidden = YES;
        }else{
            cell.delBtn.hidden = NO;
        }
        
        return cell;
        
    }else{
        //根据类创建cell
        NrowLabelViewCell *cell = [NrowLabelViewCell NrowLabelMessageViewWithTableView:tableView];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        //根据行号取出模型，赋值
        NSString *str =info[indexPath.section][@"info"][indexPath.row];
        NSLog(@"%@",str);
        cell.infoLabel.text =info[indexPath.section][@"info"][indexPath.row];
        cell.indexPath = indexPath;
        cell.parentTwoController = self;
        if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            //客户名称
            UITextField *infoTextField = (UITextField *)[cell viewWithTag:1];
            infoTextField.text = self.strHospitalName;
            
        }else if (indexPath.row == 1){
            //操作人
            UITextField *infoTextField = (UITextField *)[cell viewWithTag:1];
            infoTextField.text = self.strLinkMan;
        }else if (indexPath.row == 2){
            //科室
            UITextField *infoTextField = (UITextField *)[cell viewWithTag:1];
            infoTextField.text = self.strDepartment;
        }else if (indexPath.row == 4){
            //负责人
            UITextField *infoTextField = (UITextField *)[cell viewWithTag:1];
            infoTextField.text = self.strLinkMan;
        }else if (indexPath.row == 5){
            //电话
            UITextField *infoTextField = (UITextField *)[cell viewWithTag:1];
            infoTextField.text = self.strMobile;
        }else if (indexPath.row == 6){
            //仪器序列号
            UITextField *infoTextField = (UITextField *)[cell viewWithTag:1];
            infoTextField.text = self.strEqseq;
        }
        else if (indexPath.row == 9){
            //工单号
            UITextField *infoTextField = (UITextField *)[cell viewWithTag:1];
            infoTextField.text = self.serviceId;
        }
        if (indexPath.row == 0||indexPath.row == 1||indexPath.row == 2||indexPath.row == 3||indexPath.row == 4||indexPath.row == 5||indexPath.row == 9) {
            UITextField *textF = (UITextField *)[cell viewWithTag:1];
            [textF addTarget:self action:@selector(textClick:) forControlEvents:UIControlEventEditingChanged];
            NSLog(@"--------%@",textF.text);
            if ([textF.text isEqualToString:@""]||textF.text == nil) {
                cell.infoLabel.textColor = [UIColor redColor];
                UIView *line = (UIView *)[cell viewWithTag:3];
                line.backgroundColor = [UIColor redColor];
                
            }else{
                cell.infoLabel.textColor = [UIColor blackColor];
                UIView *line = (UIView *)[cell viewWithTag:3];
                line.backgroundColor = TBColor(212, 212, 212, 1);
            }
        }

    }
                return  cell;
    }
    
}
//设置cell的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 2) {
        return  177;
    }else{
        return 44;
    }
    
}
//设置区头
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 100)];
    view.backgroundColor = TBColor(235, 235, 235, 1);
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 50)];
    label.font = [UIFont boldSystemFontOfSize:17];
    label.text =[NSString stringWithFormat:@"  %@", info[section][@"header"]];
    
    [view addSubview:label];
    if (section == 2 || section == 3) {
        view.backgroundColor = [UIColor whiteColor];
        //服务分类（单选）
        if (section == 2) {
            //技术答疑，
            serveTypeBtnArr = [NSArray arrayWithObjects:@"投诉调查",@"异常结果处理",@"二次培训",@"软件更新培训",@"专题讲解",
                               @"系统维护",@"经销商支持(授课)",@"其他", nil];
            serveTypeBtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREENW/2, 6, SCREENW/2, 35)];
            [serveTypeBtn setTitle:serveTypeStr forState:UIControlStateNormal];
             serveTypeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            [serveTypeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            serveTypeBtn.titleLabel.font = [UIFont systemFontOfSize:16];
            [serveTypeBtn addTarget:self action:@selector(serveTypeClick) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:serveTypeBtn];
            //self.nLM.eqStyle = deviceBtn.titleLabel.text;
            
            label.tag = 3;
            UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 43, SCREENW, 1)];
            line.backgroundColor = TBColor(212, 212, 212, 1);
            line.tag = 2;
            [view addSubview:line];
            if ([serveTypeBtn.titleLabel.text isEqualToString:@""]||serveTypeBtn.titleLabel.text.length == 0) {
                line.backgroundColor = [UIColor redColor];
                label.textColor = [UIColor redColor];
            }else{
               line.backgroundColor = TBColor(212, 212, 212, 1);
               label.textColor = [UIColor blackColor];
            }
        }
        //本次服务完成状态（单选）
        if (section == 3) {
            //已完成
            MyButton *finishBtn= [MyButton buttonWithType:UIButtonTypeCustom];
            finishBtn.frame = CGRectMake(9, 45, SCREENW * 1/3, 30);
            finishBtn.tag = 20;
            [finishBtn setTitle:@"已完成" forState:UIControlStateNormal];
            [finishBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [finishBtn addTarget:self action:@selector(finishBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            finishBtn.selected = isFinish;
            if (finishBtn.selected ) {
                [finishBtn setImage:[UIImage imageNamed:@"checkbox1_checked"] forState:UIControlStateNormal];
                
                UILabel *label = [self.view viewWithTag:19];
                label.textColor = [UIColor blackColor];
                
            }else{
                [finishBtn setImage:[UIImage imageNamed:@"checkbox1_unchecked"] forState:UIControlStateNormal];
            }
            [view addSubview:finishBtn];
            
            //未完成
            MyButton *unFinishBtn= [MyButton buttonWithType:UIButtonTypeCustom];
            unFinishBtn.frame = CGRectMake(SCREENW/3 + 18, 45, SCREENW * 1/3, 30);
            [unFinishBtn setTitle:@"已完成" forState:UIControlStateNormal];
            unFinishBtn.tag = 21;
            [unFinishBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [unFinishBtn addTarget:self action:@selector(unFinishBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            unFinishBtn.selected = isUnFinish;
            if (unFinishBtn.selected ) {
                [unFinishBtn setImage:[UIImage imageNamed:@"checkbox1_checked"] forState:UIControlStateNormal];
                UILabel *label = [self.view viewWithTag:19];
                label.textColor = [UIColor blackColor];
                
                
            }else{
                [unFinishBtn setImage:[UIImage imageNamed:@"checkbox1_unchecked"] forState:UIControlStateNormal];
            }
            
            [view addSubview:unFinishBtn];
            
            if (unFinishBtn.selected||finishBtn.selected) {
                label.textColor = [UIColor blackColor];
            }else{
                label.textColor = [UIColor redColor];
            }
        }
        
        return view;
        
    }
    
    return view;
    
}
//已完成点击事件
-(void)finishBtnClick:(UIButton *)btn{
    
    UIButton *b = [(UIButton *)self.view viewWithTag:21];
    
    btn.selected = !btn.selected;
    if (btn.selected) {
        [btn setImage:[UIImage imageNamed:@"checkbox1_checked"] forState:UIControlStateNormal];
        UILabel *label = (UILabel *)[self.view viewWithTag:19];
        label.textColor = [UIColor blackColor];
        b.selected = NO;
        
    }else{
        [btn setImage:[UIImage imageNamed:@"checkbox1_unchecked"] forState:UIControlStateNormal];
    }
    isFinish = btn.selected;
    isUnFinish = b.selected;
    [tableV reloadData];
    
    
}
//未完成点击事件
-(void)unFinishBtnClick:(UIButton *)btn{
    UIButton *b = [(UIButton *)self.view viewWithTag:20];
    btn.selected = !btn.selected;
    if (btn.selected) {
        [btn setImage:[UIImage imageNamed:@"checkbox1_checked"] forState:UIControlStateNormal];
        UILabel *label = [self.view viewWithTag:19];
        label.textColor = [UIColor blackColor];
        b.selected = NO;
        
    }else{
        [btn setImage:[UIImage imageNamed:@"checkbox1_unchecked"] forState:UIControlStateNormal];
    }
    isUnFinish = btn.selected;
    isFinish = b.selected;
    [tableV reloadData];
    
}

//设备类型点击事件生成View
-(void)serveTypeClick{
    NSLog(@"设备点击了");
    
    UIView *bigView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
    bigView.backgroundColor = TBColor(237, 236, 237, .5);
    bigView.tag = 9;
    [self.view addSubview:bigView];
    
    //字体线变黑
    UILabel *label = (UILabel *)[self.view viewWithTag:2];
    label.textColor = [UIColor blackColor];
    UIView *deviceLine = (UIView *)[self.view viewWithTag:3];
    deviceLine.backgroundColor = TBColor(212, 212, 212, 1);

    singleView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, SCREENH - 150, SCREENW, 150)];
    singleView.tag = 1;
    singleView.backgroundColor =  [UIColor whiteColor];
    singleView.delegate = self;
    singleView.dataSource = self;
    [bigView addSubview:singleView];
}

#pragma mark pickerView代理方法
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (singleView.tag == 1) {
        return serveTypeBtnArr.count;
    }else if (singleView.tag == 5){
        return satisfiedArr.count;
    }
    
    return  serveFinishArr.count;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (singleView.tag == 1) {
        return serveTypeBtnArr[row];
    }else if (singleView.tag == 5){
        return satisfiedArr[row];
    }
    return serveFinishArr[row];
    
}
// pickerView滚动结束时调用
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (singleView.tag == 1) {
        [serveTypeBtn setTitle:serveTypeBtnArr[row]forState:UIControlStateNormal];
        serveTypeStr = serveTypeBtnArr[row];
        currentServeReprot.serviceType = serveTypeBtn.titleLabel.text;
        UIView *subviews  = [self.view viewWithTag:9];
        [subviews removeFromSuperview];
    }
    if (singleView.tag == 5) {
        [satisfiedBtn setTitle:satisfiedArr[row] forState:UIControlStateNormal];
        satisfiedStr = satisfiedArr[row];
        UIView *subviews  = [self.view viewWithTag:8];
        [subviews removeFromSuperview];
        
    }

    
}

//区头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 3 ) {
        return 82;
        
    }else if (section == 2) {
        return 40;
    }else{
        return 50;
    }
}
//设置区尾View
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    footView = [[UIView alloc]initWithFrame:CGRectMake(0, -30, SCREENW, 400)];
    footView.backgroundColor = [UIColor whiteColor];
    //服务分类（单选）
    if (section == 2) {

        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 19, 156, 21)];
        label.text = @"服务主要内容";
        label.font = [UIFont boldSystemFontOfSize:17];
        [footView addSubview:label];
        
        UITextView *textV = [[UITextView alloc]initWithFrame:CGRectMake(18, 42, SCREENW - 40, 150)];
        textV.layer.borderColor = TBColor(212, 212, 212, 1).CGColor;
        textV.layer.borderWidth = 1;
        [footView addSubview:textV];
        
        UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(20, 204, SCREENW - 40, 50)];
        labelTwo.text = @"解决方案简述:(仅针对投诉调查或异常结果处理)";
        labelTwo.numberOfLines = 0;
        labelTwo.font = [UIFont boldSystemFontOfSize:17];
        [footView addSubview:labelTwo];
        
        UITextView *textVTwo =[[UITextView alloc]initWithFrame:CGRectMake(18, 264, SCREENW - 40, 150)];
        textVTwo.layer.borderColor = TBColor(212, 212, 212, 1).CGColor;
        textVTwo.layer.borderWidth = 1;
        [footView addSubview:textVTwo];
        return footView;
        
    }
    
    //本次服务完成状态（单选）
    if (section == 3) {
        
        //下边的线
        UIView *bottomL = [[UIView alloc]initWithFrame:CGRectMake(0, 280, SCREENW , 2)];
        bottomL.backgroundColor = TBColor(202, 202, 202, 1);
        [footView addSubview:bottomL];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20,14, 282,21)];
        label.font = [UIFont boldSystemFontOfSize:17];
        label.text = @"如果未完成，请写明原因:";
        [footView addSubview:label];
        
        UITextView *textFinishV = [[UITextView alloc]initWithFrame:CGRectMake(21, 45, SCREENW - 42, 112)];
        textFinishV.layer.backgroundColor = TBColor(202, 202, 202, 1).CGColor;
        textFinishV.layer.borderWidth = 1;
        textFinishV.backgroundColor = [UIColor whiteColor];
        [footView addSubview:textFinishV];
        
        UITextView *textV = [[UITextView alloc]initWithFrame:CGRectMake(21, 174, SCREENW - 42, 85)];
        textV.text = @"若此次工作报告与上栏列为""已完成"",表示次维修已符合用户要求，仪器已恢复正常工作状态，如用户对此次维修有任何异.，请与三十天内以书面通知我公司";
        textV.userInteractionEnabled = NO;
        textV.font = [UIFont systemFontOfSize:16];
        [footView addSubview:textV];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        btn.frame = CGRectMake(10, 341, SCREENW - 20, 54);
        [btn setTitle:@"请输入签名" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        btn.titleLabel.font = [UIFont systemFontOfSize:17];
        btn.backgroundColor = TBColor(237, 237, 237, 1);
        btn.layer.borderColor = TBColor(181, 181, 182, 1).CGColor;
        btn.layer.borderWidth = 1;
        btn.hidden = NO;
        [btn addTarget:self action:@selector(signClick:) forControlEvents:UIControlEventTouchUpInside];
        [footView addSubview:btn];
        
        signImgView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 337, SCREENW - 20, 150)];
        signImgView.backgroundColor = TBColor(212, 212, 212, 1);
        signImgView.hidden = YES;
        [footView addSubview:signImgView];
        
        //满意度
        UILabel *satisfiedL = [[UILabel alloc]initWithFrame:CGRectMake(10, 287, SCREENW/5, 30)];
        satisfiedL.text = @"满意度:";
        satisfiedL.textColor = [UIColor blackColor];
        [footView addSubview:satisfiedL];
        
        satisfiedArr = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil];
        satisfiedBtn = [[UIButton alloc]initWithFrame:CGRectMake( SCREENW/5 + 10, 287, SCREENW - SCREENW /5 - 20 , 30)];
        satisfiedBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [satisfiedBtn setTitle:satisfiedStr forState:UIControlStateNormal];      
        [satisfiedBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [satisfiedBtn addTarget:self action:@selector(satisfiedClick) forControlEvents:UIControlEventTouchUpInside];
        [footView addSubview:satisfiedBtn];
        
        UIView *satisfiedLine = [[UIView alloc]initWithFrame:CGRectMake(0, 320, SCREENW, 1)];
        satisfiedLine.backgroundColor = TBColor(212, 212, 212, 1);
        [footView addSubview:satisfiedLine];
        
    }
    
    return  footView;
}
//点击签名事件
-(void)signClick:(UIButton *)btn{
    NSLog(@"点击了签名");
    SignsViewController *signVC = [[SignsViewController alloc]init];
    [self presentViewController:signVC animated:YES completion:nil];
    
    signVC.isBtn = ^(BOOL isBtn){
        btn.hidden = NO;
        signImgView.hidden = YES;
    };
    
    signVC.block = ^(UIImage *img){
        btn.hidden = YES;
        signImgView.image = img;
        signImgView.hidden = NO;
    };
}
//满意度点击事件
-(void)satisfiedClick{
    
    NSLog(@"满意度点击了");
    UIView *bigView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
    bigView.backgroundColor = [UIColor clearColor];
    bigView.tag = 8;
    [self.view addSubview:bigView];
    
    singleView = [[UIPickerView alloc]initWithFrame:CGRectMake(10, SCREENH - saveBtn.bounds.size.height - 150, SCREENW - 20, 150)];
    singleView.backgroundColor = [UIColor whiteColor];
    singleView.layer.masksToBounds = YES;
    singleView.tag = 5;
    singleView.delegate = self;
    singleView.dataSource = self;
    [bigView addSubview:singleView];
    
    
}
//区尾的高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if ( section == 2 ) {
        return 420;
    }else if (section == 3){
        return 500;
    }else if (section == 1){
        return 1;
    }
    return 0;
}

@end
